package com.example.myapplication.base.network.interceptor;



import java.io.IOException;


import okhttp3.Headers;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

/**
 * ParamsInterceptor 用来添加通用请求参数的网络拦截器，主要添加 timestamp，sign
 * <p/>
 */

public class ParamsInterceptor implements Interceptor {
    private static final String TAG = "请求参数";


    public ParamsInterceptor( ){
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request orgRequest = chain.request();
//        RequestBody body = orgRequest.body();
//        Headers orgHeaders = orgRequest.headers();
//        Headers newHeaders = null;
//        Request.Builder builder = orgRequest.newBuilder();
//        if (orgHeaders != null) {
//            newHeaders = addHeaders(orgHeaders);
//            builder.headers(newHeaders);
//        }
//
//        Request newRequest = builder.build();
        return chain.proceed(orgRequest);
    }

    /**
     * 添加头部信息
     *
     * @param headers
     * @return
     */
    private Headers addHeaders(Headers headers) {

        Headers.Builder builder = headers.newBuilder();
        builder.addAll(headers);
//        builder.addAll(headers);
//        builder.add("token",getToken());
//        if (getHeaderParameters() != null) {
//            Iterator it = getHeaderParameters().entrySet().iterator();
//            while (it.hasNext()) {
//                Map.Entry entry = (Map.Entry) it.next();
//                String key = (String) entry.getKey();
//                String value = (String) entry.getValue();
//                builder.add(key, value);
//            }
//        }
        return builder.build();
    }
}
